home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / ucrasm27.zip / SOURCE.ZIP / RMVCUR.ASM < prev    next >
Assembly Source File  |  1992-03-12  |  4KB  |  179 lines

  1.  
  2. ; Need to include "lists.a" in order to get list structure definition.
  3.  
  4.         include    lists.a
  5.  
  6.  
  7. wp        equ    <word ptr>        ;I'm a lazy typist
  8.  
  9.  
  10. ; Special case to handle MASM 6.0 vs. all other assemblers:
  11. ; If not MASM 5.1 or MASM 6.0, set the version to 5.00:
  12.  
  13.         ifndef    @version
  14. @version    equ    500
  15.         endif
  16.  
  17.  
  18.  
  19. StdGrp        group    stdlib,stddata
  20. stddata        segment    para public 'sldata'
  21. stddata        ends
  22.  
  23. stdlib        segment    para public 'slcode'
  24.         assume    cs:stdgrp
  25.  
  26. ; sl_RemoveCur -    ES:DI points at a list.
  27. ;            Removes the CurrentNode from the list and returns a
  28. ;            pointer to this item in DX:SI.  Returns the carry
  29. ;            flag set if the list was empty.
  30. ;
  31. ; Randall Hyde  3/12/92
  32. ;
  33.  
  34.         public    sl_RemoveCur
  35. sl_RemoveCur    proc    far
  36.         push    ds
  37.         push    ax
  38.         push    es
  39.         push    di
  40.  
  41.         if    @version ge 600
  42.  
  43. ; MASM 6.0 version goes here
  44.  
  45.         cmp    wp es:[di].List.Tail+2, 0    ;Empty list?
  46.         jne    HasAList
  47.  
  48. ; At this point, the Tail pointer is zero.  This only occurs if the
  49. ; list is empty.
  50. ;
  51. ; Note: Technically, the NIL pointer is 32-bits of zero. However, this
  52. ; package assumes that if the segment is zero, the whole thing is zero.
  53. ; So don't put any nodes into segment zero!
  54.  
  55.         xor    dx, dx                ;Set DX:SI to NIL.
  56.         mov    si, dx
  57.         pop    di
  58.         pop    es
  59.         stc
  60.         jmp    RemoveDone
  61.  
  62. ; If the HEAD pointer is NON-NIL, remove the CurrentNode here.
  63.  
  64. HasAList:    lds    si, es:[di].List.CurrentNode    ;Get node to delete.
  65.  
  66. ; Remove this guy by doing the following:
  67. ;
  68. ; +----------+       +----------+       +----------+
  69. ; |          | -->   |          | -->   |          |
  70. ; +----------+       +----------+       +----------+
  71. ;
  72. ; First, set the next field of the previous node to point at the next field
  73. ; of the current node:
  74. ;
  75. ; +----------+       +----------+       +----------+
  76. ; |          | -+    |          |   +-> |          |
  77. ; +----------+  |    +----------+   |   +----------+
  78. ;               +-------------------+
  79.  
  80.         cmp    wp ds:[si].Node.Prev+2, 0    ;No previous node?
  81.         je    CurrentIs1st
  82.         les    di, ds:[si].Node.Prev
  83.         mov    dx, wp ds:[si].Node.Next
  84.         mov    wp es:[di].Node.Next, dx
  85.         mov    dx, wp ds:[si].Node.Next+2
  86.         mov    wp es:[di].Node.Next+2, dx
  87.         jmp    short FixNextNode
  88.  
  89. ; If there was no first node, then the current node is the first node in
  90. ; the list.  We need to patch the HEAD pointer in this case.
  91.  
  92. CurrentIs1st:    pop    di                ;Get ptr to list
  93.         pop    es
  94.         push    es
  95.         push    di
  96.         mov    dx, wp ds:[si].Node.Next
  97.         mov    wp es:[di].List.Head, dx
  98.         mov    dx, wp ds:[si].Node.Next+2
  99.         mov    wp es:[di].List.Head+2, dx
  100.  
  101. ; Next, set the previous field of the next node to point at the previous
  102. ; node:
  103. ;
  104. ; +----------+       +----------+       +----------+
  105. ; |          | <--   |          | <--   |          |
  106. ; +----------+       +----------+       +----------+
  107. ;
  108. ; +----------+       +----------+       +----------+
  109. ; |          | <-+   |          |    +- |          |
  110. ; +----------+   |   +----------+    |  +----------+
  111. ;                +-------------------+
  112.  
  113. FixNextNode:    cmp    wp ds:[si].Node.Next+2, 0    ;No next node?
  114.         je    CurrentIsLast
  115.         les    di, ds:[si].Node.Next
  116.         mov    dx, wp ds:[si].Node.Prev
  117.         mov    wp es:[di].Node.Prev, dx
  118.         mov    ax, wp ds:[si].Node.Prev+2
  119.         mov    wp es:[di].Node.Prev+2, dx
  120.  
  121.         mov    dx, es                ;Save ptr to new
  122.         mov    ax, di                ; current node
  123.         pop    di
  124.         pop    es
  125.         mov     wp es:[di].List.CurrentNode, ax
  126.         mov    wp es:[di].List.CurrentNode+2, dx
  127.         jmp    GoodRemove
  128.  
  129. ; If the current node was the last node in the list, we've got to patch the
  130. ; TAIL pointer in the list structure.
  131.  
  132. CurrentIsLast:    cmp    wp ds:[si].Node.Prev+2, 0    ;Was this the only
  133.         je    OnlyNodeInList            ; node?
  134.  
  135.         pop    di
  136.         pop    es
  137.  
  138.         mov    dx, wp ds:[si].Node.Prev
  139.         mov    wp es:[di].List.Tail, dx
  140.         mov    wp es:[di].List.CurrentNode, dx
  141.         mov    dx, wp ds:[si].Node.Prev+2
  142.         mov    wp es:[di].List.Tail+2, dx
  143.         mov    wp es:[di].List.CurrentNode+2, dx
  144.         jmp    GoodRemove
  145.  
  146.  
  147. ; If the current node was the only node in the list, set the TAIL and
  148. ; CurrentNode fields to NIL.  Note that HEAD was already set to NIL.
  149.  
  150. OnlyNodeInList:    pop    di
  151.         pop    es
  152.         xor    dx, dx
  153.         mov    wp es:[di].List.Tail, dx
  154.         mov    wp es:[di].List.Tail+2, dx
  155.         mov    wp es:[di].List.CurrentNode, dx
  156.         mov    wp es:[di].List.CurrentNode+2, dx
  157.  
  158.  
  159.         else
  160.  
  161. ; Handle other assemblers down here
  162.  
  163.  
  164.  
  165.         endif
  166.  
  167. GoodRemove:    clc
  168.         mov    dx, ds            ;Return ptr to node we've
  169. ;                        ; removed in DX:SI.
  170.  
  171. RemoveDone:    pop    ax
  172.         pop    ds
  173.         ret
  174.  
  175. sl_RemoveCur    endp
  176.  
  177. stdlib        ends
  178.         end
  179.